package com.hctforgreen.greenservice;

import android.annotation.SuppressLint;
import android.app.Activity;
import android.content.Intent;
import android.graphics.Color;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.text.TextUtils;
import android.view.View;
import android.widget.ImageButton;
import android.widget.LinearLayout;
import android.widget.TextView;
import android.widget.Toast;

import com.hctforgreen.greenservice.utils.ContantsUtil;

public class HomeRepairInstallActivity extends ParentActivity implements
        View.OnClickListener {
    private static final String TAG = "HomeRepInsActivity";
    private LinearLayout mLlHomeInstall;
    private LinearLayout mLlHomeRepair;
    private LinearLayout mLlHomeInstallRepair;
    private TextView mTvHomeInstall, mTvHomeRepair, mTvHomeInstallRepair;

    public static Handler sHandler;

    /**
     * 外部Activity启动本Activity
     *
     * @param activity
     */
    public static void launch(Activity activity) {
        Intent intent = new Intent(activity, HomeRepairInstallActivity.class);
        activity.startActivity(intent);
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_home_repair_install);

        initSkinLayout();
        initView();
        initTitleButtonBar();
        initLayout();
        initHandler();
    }

    private void initView() {
        mLlHomeInstall = (LinearLayout) findViewById(R.id.lyt_new_home_install);
        mLlHomeInstall.setOnClickListener(this);
        mLlHomeRepair = (LinearLayout) findViewById(R.id.lyt_new_home_repair);
        mLlHomeRepair.setOnClickListener(this);
        mLlHomeInstallRepair = (LinearLayout) findViewById(R.id.lyt_new_install_repair);
        mLlHomeInstallRepair.setOnClickListener(this);
        mTvHomeInstall = (TextView) findViewById(R.id.tvHomeInstall);
        mTvHomeRepair = (TextView) findViewById(R.id.tvHomeRepair);
        mTvHomeInstallRepair = (TextView) findViewById(R.id.tvHomeInstallRepair);
    }

    private void initTitleButtonBar() {
        final TextView titleTv = (TextView) findViewById(R.id.tv_title);
        titleTv.setText("家用培训及验收");

        final ImageButton backBtn = (ImageButton) findViewById(R.id.btn_back);
        backBtn.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                finish();
            }
        });
    }

    private void initLayout() {
        if (TextUtils.isEmpty(ContantsUtil.sStaffRole)) {
            Toast.makeText(this, "您暂时没有家用培训身份", Toast.LENGTH_SHORT).show();
            finish();
        } else if (ContantsUtil.sStaffRole.equals(ContantsUtil.mRoles[0]) ||
                ContantsUtil.sStaffRole.equals(ContantsUtil.mRoles[3])) {    //家用空调安装
            mLlHomeInstall.setClickable(true);
            mTvHomeInstall.setTextColor(Color.BLACK);
            mLlHomeRepair.setClickable(false);
            mTvHomeRepair.setTextColor(0xffaaaaaa);
            mLlHomeInstallRepair.setClickable(false);
            mTvHomeInstallRepair.setTextColor(0xffaaaaaa);
        } else if (ContantsUtil.sStaffRole.equals(ContantsUtil.mRoles[1]) ||
                ContantsUtil.sStaffRole.equals(ContantsUtil.mRoles[4])) { //家用空调维修
            mLlHomeRepair.setClickable(true);
            mTvHomeRepair.setTextColor(Color.BLACK);
            mLlHomeInstall.setClickable(false);
            mTvHomeInstall.setTextColor(0xffaaaaaa);
            mLlHomeInstallRepair.setClickable(false);
            mTvHomeInstallRepair.setTextColor(0xffaaaaaa);
        } else if (ContantsUtil.sStaffRole.equals(ContantsUtil.mRoles[2]) ||
                ContantsUtil.sStaffRole.equals(ContantsUtil.mRoles[5])) { //家用空调安装和维修
            mLlHomeInstallRepair.setClickable(true);
            mTvHomeInstallRepair.setTextColor(Color.BLACK);
            mLlHomeInstall.setClickable(false);
            mTvHomeInstall.setTextColor(0xffaaaaaa);
            mLlHomeRepair.setClickable(false);
            mTvHomeRepair.setTextColor(0xffaaaaaa);
        } else {//除了这6种身份之外的其他3种合法身份
            Toast.makeText(this, "您暂时没有家用空调身份", Toast.LENGTH_SHORT).show();
            finish();
        }
    }

    @SuppressLint("HandlerLeak")
    private void initHandler() {
        sHandler = new Handler() {
            @Override
            public void handleMessage(Message msg) {
                switch (msg.what) {
                    default:
                        break;
                }
            }
        };
    }

    @Override
    protected void onResume() {
        super.onResume();
    }

    @Override
    protected void onPause() {
        super.onPause();
    }

    @Override
    public void onBackPressed() {
        super.onBackPressed();
    }

    @Override
    public void onClick(View v) {
        Intent intent = null;
        switch (v.getId()) {
            case R.id.lyt_new_home_install:
                intent = new Intent(this, NewStudentTrainActivity.class);
                intent.putExtra("studyTypeId", "");
                intent.putExtra("personId", "");
                String childtypeId2 = "";
                intent.putExtra("childtypeId", childtypeId2);
                intent.putExtra("searchKey", "");
                intent.putExtra("trainType", "0");
                startActivity(intent);
                break;
            case R.id.lyt_new_home_repair:
                intent = new Intent(this, NewStudentTrainActivity.class);
                intent.putExtra("studyTypeId", "");
                intent.putExtra("personId", "");
                String childtypeId3 = "";
                intent.putExtra("childtypeId", childtypeId3);
                intent.putExtra("searchKey", "");
                intent.putExtra("trainType", "1");
                startActivity(intent);
                break;
            case R.id.lyt_new_install_repair:
                intent = new Intent(this, NewStudentTrainActivity.class);
                intent.putExtra("studyTypeId", "");
                intent.putExtra("personId", "");
                String childtypeId4 = "";
                intent.putExtra("childtypeId", childtypeId4);
                intent.putExtra("searchKey", "");
                intent.putExtra("trainType", "2");
                startActivity(intent);
                break;
            default:
                break;
        }
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
    }
}
